package com.zhangsr.zus.config.spring;

import com.zhangsr.zus.config.api.ZusReferenceConfig;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @Author: zhangsr
 */
public class ReferenceBean<T> extends ZusReferenceConfig<T>
        implements FactoryBean, ApplicationContextAware, InitializingBean, DisposableBean {

    private transient ApplicationContext applicationContext;

	public ReferenceBean() {
        super();
    }

    /**
     * 通过 ApplicationContextAware 获取 ApplicationContext 实例
     * <p/>
     * Using implements ApplicationContextAware
     */
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public Object getObject() throws Exception {
        return get();
    }

    public Class<?> getObjectType() {
        return getInterfaceClass();
    }

    public boolean isSingleton() {
        return true;
    }

    public void afterPropertiesSet() throws Exception {
    }
}
